executeJavascript

open fun executeJavascript(script: String)

Execute the supplied Javascript within the loaded web page.

Parameters

script

The Javascript to execute.


open fun executeJavascript(script: String, callback: ValueCallback<String>)

Execute the supplied Javascript within the loaded web page.

For devices running Android versions prior to KitKat (API level 19), the Javascript will be executed by calling loadUrl("javascript:" + script). For KitKat and newer versions, evaluateJavascript(script, callback) will be used. The execution is posted to the view's message queue to ensure it runs on the UI thread.

Parameters

script

The Javascript to execute. If null, the method will return without doing anything.

callback

A ValueCallback to be invoked with the result of the Javascript execution. This callback will only be used on devices running KitKat (API level 19) or newer. On older devices, this parameter is ignored, and the callback will not be invoked. The callback will receive a JSON representation of the result.